package com.mindskip.xzs.utility.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.mindskip.xzs.domain.enums.ExamTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


/**
 * <p>
 * 针对JDK8的LocalDate类型，easyexcel默认的类型转换器是无法处理的，要自行编写转换器
 * </p>
 *
 * @author guoguangkai
 * @since 2022/1/25
 */
@Slf4j
@Component
public class ExamTypeConverter implements Converter<Integer> {

    @Override
    public WriteCellData<Integer> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        try {
            return new WriteCellData<Integer>(ExamTypeEnum.of(value).getName());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return new WriteCellData<Integer>("未知");
        }
    }
}
